package com.ljx.recruitment.user.controller;

import com.ljx.recruitment.common.domain.vo.resp.ApiResult;
import com.ljx.recruitment.common.domain.vo.resp.PageResp;
import com.ljx.recruitment.security.annotation.ApiPermission;
import com.ljx.recruitment.security.common.PermissionConstant;
import com.ljx.recruitment.user.domain.entity.Menu;
import com.ljx.recruitment.user.domain.vo.req.MenuPageReq;
import com.ljx.recruitment.user.domain.vo.req.MenuSubmitReq;
import com.ljx.recruitment.user.domain.vo.req.MenuToRoleReq;
import com.ljx.recruitment.user.service.MenuService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: LiJunXi
 * @Description:
 * @Date: 2024-11-14  22:40
 */
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    @ApiPermission(permissions = {PermissionConstant.MENU_QUERY})
    @ApiOperation("获取菜单分页")
    @GetMapping("/page")
    public ApiResult<PageResp<Menu>> getPage(MenuPageReq req) {
        return ApiResult.success(menuService.getPage(req));
    }

    @ApiPermission(permissions = {PermissionConstant.MENU_SUBMIT})
    @ApiOperation("创建/修改菜单")
    @PostMapping("/submit")
    public ApiResult<Menu> submit(@Validated @RequestBody MenuSubmitReq req){
        return ApiResult.success(menuService.submit(req));
    }

    @ApiPermission(permissions = {PermissionConstant.MENU_SUBMIT, PermissionConstant.ROLE_SUBMIT})
    @ApiOperation("给角色分配菜单")
    @PostMapping("/toRole")
    public ApiResult<Void> allocationToRole(@Validated @RequestBody MenuToRoleReq req){
        menuService.allocationToRole(req);
        return ApiResult.success();
    }
}
